package com.ygk.bluepath.member.View;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.ygk.bluepath.R;
import com.ygk.bluepath.core.BFragment;
import com.ygk.bluepath.member.Presenter.RegisterPresenterFragmentOne;

import cn.smssdk.SMSSDK;

/**
 * Created by Handreace on 16-7-13.
 */
public class RegisterFragmentOne extends BFragment implements View.OnClickListener,RegisterFragmentOneView {
    private View mRootView;

    @ViewInject(R.id.et_name)
    private EditText et_name;
    @ViewInject(R.id.et_password)
    private EditText et_password;
    @ViewInject(R.id.tv_next)
    private TextView tv_next;
    @ViewInject(R.id.tv_send_code)
    private TextView tv_send_code;

    private RegisterPresenterFragmentOne registerPresenterFragmentOne;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_register_step1, container, false);
        ViewUtils.inject(this,mRootView);
        registerPresenterFragmentOne = new RegisterPresenterFragmentOne(this, this);
        initView();
        return mRootView;
    }

    private void initView() {

        // ((ImageView) mRootView.findViewById(R.id.iv_step)).setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher));

        mRootView.findViewById(R.id.tv_send_code).setOnClickListener(this);
        mRootView.findViewById(R.id.tv_next).setOnClickListener(this);

    }


    @Override
    public void onStart() {
        super.onStart();
        registerPresenterFragmentOne.initMob();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){

            case R.id.tv_send_code://发送验证码
                registerPresenterFragmentOne.sendCode(((EditText)mRootView.findViewById(R.id.et_mobile)).getText().toString());
                break;
            case R.id.tv_next://下一步
                registerPresenterFragmentOne.submitCode(((EditText)mRootView.findViewById(R.id.et_mobile)).getText().toString(),((EditText)mRootView.findViewById(R.id.et_code)).getText().toString());
                break;
        }
    }

    @Override
    public void onDestroy() {
        registerPresenterFragmentOne.unregisterMob();
        super.onDestroy();
    }

    @Override
    public void onStop() {
        registerPresenterFragmentOne.unregisterMob();
        super.onStop();
    }
}
